package com.Servlet;

import com.dao.DaoFactory;
import com.entity.book;
import com.entity.book_examine;
import com.entity.search;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class mybookServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setHeader("Cache-control", "no-cache");
        request.setCharacterEncoding("UTF-8");

        HttpSession session = request.getSession();
        String author_name = (String) session.getAttribute("author_name");

        try {
            List<search> mybook= DaoFactory.getInstance().getsearchDao().findbyauthor(author_name);
            List<book_examine> book_examine = DaoFactory.getInstance().getbook_examineDao().findbyauthor(author_name);
            if(mybook == null){
                request.setAttribute("nobook",1);
            }
            else {
                request.setAttribute("nobook",0);
            }
            if(book_examine.size() == 0){
                request.setAttribute("be",0);
            }
            else {
                request.setAttribute("be",1);
            }
            request.setAttribute("mybook",mybook);
            request.setAttribute("book_examine",book_examine);
            request.getRequestDispatcher("mybook.jsp").forward(request,response);
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }

}
